|
|
@@ -228,10 +228,10 @@ module Agents
|
228
|
228
|
end
|
229
|
229
|
|
230
|
230
|
case index = details['index']
|
231
|
|
- when Integer
|
|
231
|
+ when Integer, /\A\d+\z/
|
232
|
232
|
# ok
|
233
|
233
|
when String
|
234
|
|
- if index.to_i.to_s != index && re && !re.names.include?(index)
|
|
234
|
+ if re && !re.names.include?(index)
|
235
|
235
|
errors.add(:base, "no named capture #{index.inspect} found in regexp for #{name.inspect})")
|
236
|
236
|
end
|
237
|
237
|
when nil
|
|
|
@@ -427,13 +427,13 @@ module Agents
|
427
|
427
|
def extract_text(doc)
|
428
|
428
|
extract_each { |extraction_details|
|
429
|
429
|
regexp = Regexp.new(extraction_details['regexp'])
|
|
430
|
+ case index = extraction_details['index']
|
|
431
|
+ when /\A\d+\z/
|
|
432
|
+ index = index.to_i
|
|
433
|
+ end
|
430
|
434
|
result = []
|
431
|
435
|
doc.scan(regexp) {
|
432
|
|
- index_or_named_group = extraction_details['index']
|
433
|
|
- if index_or_named_group.is_a?(String) && index_or_named_group.to_i.to_s == index_or_named_group
|
434
|
|
- index_or_named_group = index_or_named_group.to_i
|
435
|
|
- end
|
436
|
|
- result << Regexp.last_match[index_or_named_group]
|
|
436
|
+ result << Regexp.last_match[index]
|
437
|
437
|
}
|
438
|
438
|
log "Extracting #{extraction_type} at #{regexp}: #{result}"
|
439
|
439
|
result
|